﻿@model CountryListModel
@using Telerik.Web.Mvc.UI
@{
    ViewBag.Title = T("Admin.Configuration.Countries").Text;
}
<div class="section-header">
    <div class="title">
        <i class="fa fa-globe"></i>
        @T("Admin.Configuration.Countries")
    </div>
    <div class="options">
        <a href="@Url.Action("Create")" class="btn btn-primary">
			<i class="fa fa-plus"></i>
			<span>@T("Admin.Common.AddNew")</span>
		</a>
    </div>
</div>

<div>
	@(Html.Telerik().Grid<CountryModel>()
		.Name("countries-grid")
		.DataKeys(x =>
		{
			x.Add(y => y.Id).RouteKey("Id");
		})
		.Editable(x =>
		{
			x.Mode(GridEditMode.InLine);
		})
		.Columns(columns =>
		{
			columns.Bound(x => x.Name)
				.ClientTemplate("<a href='Edit/<#= Id #>'><#= Name #></a>")
				.Width("30%");
			columns.Bound(x => x.AllowsBilling)
					.Width("10%")
					.ClientTemplate(@Html.SymbolForBool("AllowsBilling"))
					.Centered();
			columns.Bound(x => x.AllowsShipping)
					.ClientTemplate(@Html.SymbolForBool("AllowsShipping"))
					.Width("10%")
					.Centered();
			columns.Bound(x => x.TwoLetterIsoCode)
				.Hidden(true);
			columns.Bound(x => x.ThreeLetterIsoCode)
				.Hidden(true);
			columns.Bound(x => x.NumericIsoCode)
				.Hidden(true);
			columns.Bound(x => x.SubjectToVat)
					.ClientTemplate(@Html.SymbolForBool("SubjectToVat"))
					.Width("10%")
					.Centered();
			columns.Bound(x => x.DisplayOrder)
				.Width("10%")
				.Centered();
			columns.Bound(x => x.LimitedToStores)
				.Width("10%")
				.Hidden(true);
			columns.Bound(x => x.Published)
					.ClientTemplate(@Html.SymbolForBool("Published"))
					.Width("10%")
					.Centered();
			columns.Command(commands =>
			{
				commands.Edit().Localize(T);
				commands.Delete().Localize(T);
			}).Width("20%").HtmlAttributes(new { align = "right" });
		})
		.DataBinding(dataBinding => dataBinding.Ajax()
			.Select("CountryList", "Country")
			.Update("CountryUpdate", "Country")
			.Delete("CountryDelete", "Country")
		)
		.ClientEvents(x => x.OnError("CountryGrid_onError"))
		.PreserveGridState()
		.EnableCustomBinding(true))
</div>

<script type="text/javascript">
	function CountryGrid_onError(e) {
		e.preventDefault();
        alert(e.XMLHttpRequest.responseText);
    }
</script>
